package com.ok.api.client.fallback;

import com.ok.api.client.IntegralClient;
import com.ok.common.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @ClassName IntegralFallback
 * @Description IntegralClient远程调用失败处理
 * @Author hw
 * @Date 2024/5/8 17:13
 */
@Slf4j
public class IntegralFallback implements FallbackFactory<IntegralClient> {
    @Override
    public IntegralClient create(Throwable cause) {

        return new IntegralClient() {
            @Override
            public void add(@RequestParam("userId") Long userId) {
                log.error("远程调用IntegralClient#add方法出现异常 userId:{}",userId);
                throw new CustomException("远程调用失败");
            }

            @Override
            public void update(Double integral) {
                throw new CustomException("远程调用失败");
            }
        };
    }
}
